using Toast.Compression.Providers;
using Toast.Core;
using Toast.Core.Interfaces;

namespace Toast.Compression
{
    public class GoogleClosureCompression : IJavaScriptCompressionStrategy
    {
        #region IJavaScriptCompressionStrategy Members

        public string Compress(string script)
        {
            return CompressionLevel == CompressionLevel.None
                       ? script
                       : GoogleClosure.Compress(script, EncodingConvert(CompressionLevel));
        }

        public CompressionLevel CompressionLevel { get; set; }

        #endregion

        static string EncodingConvert(CompressionLevel compressionLevel)
        {
            switch (compressionLevel)
            {
                case CompressionLevel.High:
                    return "ADVANCED_OPTIMIZATIONS";
                case CompressionLevel.Normal:
                    return "WHITESPACE_ONLY";
                default:
                    return "SIMPLE_OPTIMIZATION";
            }
        }
    }
}